package edu.ccut.saturn.component.impl;

import java.util.Date;
import java.util.LinkedList;

import edu.ccut.saturn.component.IDebugComponentInfo;
import edu.ccut.saturn.component.IDebugThread;
import edu.ccut.saturn.component.utils.DateUtils;

public class SaturnDebugThread implements IDebugThread {
	
	private IDebugComponentInfo debugComponentInfo;
	
	private long startTime;
	
	private long endTime;
	
	private String name;
	
	private LinkedList<IDebugComponentInfo> componetInfoStack = new LinkedList<IDebugComponentInfo>();

	public SaturnDebugThread() {
		super();
	}

	public IDebugComponentInfo getDebugComponentInfo() {
		return debugComponentInfo;
	}

	public void setDebugComponentInfo(IDebugComponentInfo debugComponentInfo) {
		this.debugComponentInfo = debugComponentInfo;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public long getEndTime() {
		return endTime;
	}

	public void setEndTime(long endTime) {
		this.endTime = endTime;
	}

	public LinkedList<IDebugComponentInfo> getComponetInfoStack() {
		return componetInfoStack;
	}

	public void setComponetInfoStack(
			LinkedList<IDebugComponentInfo> componetInfoStack) {
		this.componetInfoStack = componetInfoStack;
	}

	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public IDebugComponentInfo getRuntimeDebugComponetInfo() {
		if (this.componetInfoStack.isEmpty()) {
			return null;
		} else {
			return this.componetInfoStack.getLast();
		}
	}

	public IDebugComponentInfo popRuntimeDebugComponetInfo() {
		if (this.componetInfoStack.isEmpty()) {
			return null;
		} else {
			return this.componetInfoStack.removeLast();
		}
	}

	public void pushRuntimeDebugComponetInfo(
			IDebugComponentInfo debugComponentInfo) {
		
		this.componetInfoStack.addLast(debugComponentInfo);
	}
	
	public boolean isComponentInfoStackEmpty() {
		return this.componetInfoStack.isEmpty();
	}

	public String getEndTimeStr() {
		return DateUtils.getSysteTimeMillisecond(new Date(this.endTime));
	}

	public String getStartTimeStr() {
		return DateUtils.getSysteTimeMillisecond(new Date(this.startTime));
	}
}
